package dxn.nl.file.api.export;

import com.alibaba.fastjson2.JSONObject;
import dxn.nl.file.client.core.CsExportDealServer;
import dxn.nl.file.client.core.DealExportService;
import dxn.nl.file.client.model.dto.*;
import dxn.nl.file.client.model.enums.ExportDealResultTypeEnum;
import lombok.Builder;
import lombok.Data;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Component
@CsExportDealServer(value = {"demo_export_page_has_title"})
public class DealPageHasTitleExport implements DealExportService {
    @Override
    public CsExportDealTypeHeadDto getExcelHeads(TransferMessageConfig config, TransferMessageData messageData, byte[] data) {
        List<CsExportExcelHeadDto> dtoList = Arrays.asList(new CsExportExcelHeadDto("code","编号",1,30),
                new CsExportExcelHeadDto("name","名称",2,15),
                new CsExportExcelHeadDto("age","年龄",3,10),
        new CsExportExcelHeadDto("address","地址",20));
        CsExportDealTypeHeadDto dto = CsExportDealTypeHeadDto.pageDeal(dtoList);
        return dto;
    }

    @Override
    public  CsExportDealResult queryData(TransferMessageConfig config, TransferMessageData messageData, byte[] data) {
        CsExportDealResult dealResult = new CsExportDealResult();
        dealResult.setDealResult(ExportDealResultTypeEnum.continue_deal);

        if(messageData.getCurrentParam()!=null) {
            dealResult.setDealResult(ExportDealResultTypeEnum.end);
            return dealResult;
        }

        dealResult.setCurrentParam("ceshi");
        List<JSONObject> list = new ArrayList<>();
        for(int i=0;i<10;i++)
        {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("code", "code"+i);
            jsonObject.put("name", "name"+i);
            jsonObject.put("age", "age"+i);
            jsonObject.put("address", "address"+i);
            list.add(jsonObject);
        }
        dealResult.setData(list);

        return dealResult;
    }
}
